package core;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import simulator.Simulator;

public class Main {

	private static int norm(float x){
		x = (x-850)/70;
		x = Math.signum(x)*Math.round(Math.abs(x));
		return (int)x;
	}
		
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {	
		
		System.out.println("baboom");

		System.out.println(norm(800));
		System.out.println(norm(815));
		System.out.println(norm(825));
		System.out.println(norm(840));
		System.out.println(norm(850));
		System.out.println(norm(860));
		System.out.println(norm(875));
		System.out.println(norm(885));
		System.out.println(norm(900));
		
		start(args);
		
	}
	
	private static void start(String[] args){
		Simulator.Configuration config = new Simulator.Configuration("YAKS","auto.opt");
		if(args.length == 2) config.setField("SERVER_PORT", args[1]);
		config.setField("WORLD_FILE", "test.world");
		
		Process process = Simulator.start(config);
		try {
			Thread.sleep(3000);
			ExecutorService es = Executors.newFixedThreadPool(Integer.parseInt(config.getField("A_#ROBOTS")));
			es.execute(new Mati(args[0],Integer.parseInt(config.getField("SERVER_PORT"))));
			process.waitFor();
			es.shutdownNow();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}


}
